<?php
//var_dump();
class Kmgoodstype  extends BaseModel
{
    public $res;
    public $redis_key="";
    public function getSource()
    {
        return "km_good_type";
    }
    public function initialize()
    {
        parent::initialize();

    }

    /**
     * 获取
     * is_recommend是否选择推荐
     */
    public function get_list($is_recommend=0,$data=[],$choose_columns=''){
        $condition = "goods_type_id<>-1";
        if($is_recommend){
            $condition .= " and is_recommend={$is_recommend}";
        }
        if($data['cate_id'] > 0){
            //$condition .= " and cate_id like '%{$data['cate_id']}%'";
            $condition .= " AND FIND_IN_SET('{$data['cate_id']}',cate_id)";
        }
        if($data['is_hot'] > 0){
            $condition .= " and is_hot=1 ";
        }
        $condition .= " and sell_status={$data['sell_status']}";

        if(empty($choose_columns)){
            $choose_columns='goods_type_id,goods_type_name,short_type_name,icon,product_type';
        }

        $res = $this::find(
            array(
                $condition,
                'columns'=>$choose_columns,
                'order' => 'id desc',
            )
        );
        return $res;
    }


    /**
     * 获取
     * is_recommend是否选择推荐
     */
    public function get_list1($is_recommend=0,$data=[],$choose_columns=''){
        $condition = "sell_status=1";
        if($is_recommend){
            $condition .= " and is_recommend={$is_recommend}";
        }
        if(isset($data['cate_id'])){
            //$condition .= " and cate_id like '%{$data['cate_id']}%'";
            $condition .= " AND FIND_IN_SET('{$data['cate_id']}',cate_id)";
        }
        if(isset($data['is_hot'])){
            $condition .= " and is_hot=1";
        }

        if(empty($choose_columns)){
            $choose_columns='goods_type_id,goods_type_name,up_desc,short_type_name,icon,product_type,ids';
        }

        $res = $this::find(
            array(
                $condition,
                'columns'=>$choose_columns,
            )
        )->toarray();
        $material = new Material();
        foreach($res as $key=>$value){
            if($value['ids']){
                $res[$key]['is_router']=true;
                $router=$material->getListByIds($value['ids']);
                $res[$key]['router']=$router[0];
            }else{
                $res[$key]['is_router']=false;
            }
        }
        return $res;
    }



    /*
     * 根据卡密id获取分类
     */
    public function find_by_goods_type_id($goods_type_id){
        $info = $this->findFirstByGoodsTypeId($goods_type_id);
        return $info;
    }
}
